﻿
@{
    ViewData["Title"] = "CreateWireTransfe";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'upload'], function () {
        var $ = layui.$
            , form = layui.form
            , admin = layui.admin
            , table = layui.table
            , upload = layui.upload
            , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;

        /**多语言初始化 */
        top.SetFormPageLanguage(layui);

        $.getJSON("/Console/Roles/GetListJson?userType=1", function (result) {
            let plat = result.data;
            $('#RoleId').append(new Option(top.lang.pleaseSelect, ""));
            plat.forEach(function (v) {
                for (var key in top.lang) {
                    if (top.lang.hasOwnProperty(key)) {
                        if (key === v.remark) {
                            var text = top.lang[key];
                            $('#RoleId').append(new Option(text, v.id));
                        }
                    }
                }
            });
            layui.form.render("select");
        });

        /* 监听提交 */
        form.on('submit(submit-form)', function (data) {

            //var type = $("select[name='type']").val();
            //if (type == -1) {
            //    top.AlertByKey(layui, "enterCodeType", 0);
            //    return false;
            //}
            if ($("#sort").val() == "") {
                top.AlertByKey(layui, "sortPrompt", 0);
                return false;
            }
            if ($("#MetatraderName").val() == "") {
                top.AlertByKey(layui, "serverPrompt", 0);
                return false;
            }
            if ($("#MetatraderServer").val() == "") {
                top.AlertByKey(layui, "serverAddressPrompt", 0);
                return false;
            }
            if ($("#MetatraderPort").val() == "") {
                top.AlertByKey(layui, "serverPortPrompt", 0);
                return false;
            }
            if ($("#MetatraderLogin").val() == "") {
                top.AlertByKey(layui, "inputPrompt", 0);
                return false;
            }
            if ($("#MetatraderPassword").val() == "") {
                top.AlertByKey(layui, "inputPrompt", 0);
                return false;
            }
            if ($("#StartLogin").val() == "") {
                top.AlertByKey(layui, "accountStartNoPrompt", 0);
                return false;
            }
            if ($("#EndLogin").val() == "") {
                top.AlertByKey(layui, "accountEndNoPrompt", 0);
                return false;
            }
            data.field.State = 1;
            $.ajax({
                type: "POST",
                url: "/Console/MtService/AddServerSetting",
                data: data.field, // 你的formid
                async: true,
                error: function (request) {
                    alert("Connection error");
                },
                beforeSend: function (xhr) {
                    layui.layer.load();
                },
                success: function (data) {
                    var item = eval(data);
                    if (item.code == 0) {
                        /**提示语弹框 */
                        top.ShowMessageByKey(layui, "submitSuccess", 6, 1000, function () {
                            parent.layer.close(parentFrameIndex);
                            parent.layui.table.reload("tableReload");
                        });
                    } else {
                        /**提示语弹框 */
                        top.AlertByKey(layui, "submitFail", 0);
                    }
                    layer.closeAll('loading');
                }
            });
            return false;
        });
        form.on('submit(submit-form-test)', function (data) {
            if ($("#MetatraderServer").val() == "") {
                top.AlertByKey(layui, "serverAddressPrompt", 0);
                return false;
            }
            if ($("#MetatraderPort").val() == "") {
                top.AlertByKey(layui, "serverPortPrompt", 0);
                return false;
            }
            if ($("#MetatraderLogin").val() == "") {
                top.AlertByKey(layui, "inputPrompt", 0);
                return false;
            }
            if ($("#MetatraderPassword").val() == "") {
                top.AlertByKey(layui, "inputPrompt", 0);
                return false;
            }
            $.ajax({
                type: "POST",
                url: "/Console/MtService/TestConnection",
                data: data.field, // 你的formid
                async: true,
                error: function (request) {
                    alert("Connection error");
                },
                beforeSend: function (xhr) {
                    layui.layer.load();
                },
                success: function (data) {
                    var item = eval(data);
                    if (item.code == 0) {
                        /**提示语弹框 */
                        top.ShowMessageByKey(layui, "successfullyConnected", 6, 3000, "");
                    } else {
                        /**提示语弹框 */
                        top.AlertByKey(layui, "connectFailed", 0);
                    }
                    layer.closeAll('loading');
                }
            });
            return false;

        });


    });
</script>
<div class="layui-fluid">
    <div class="layui-row ">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="component-form-element">
                    <div class="layui-row layui-col-space12">
                        @*<div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="accountType">类型</label>
                            <div class="layui-input-block">
                                <select name="type" id="type">
                                    <option value="-1" lay-event="pleaseSelect">请选择</option>
                                    <option value="0" lay-event="imitate">模拟</option>
                                    <option value="1" lay-event="real">真实</option>
                                </select>
                            </div>
                        </div>*@
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="sort">排序</label>
                            <div class="layui-input-block">
                                <input type="text" name="sort" id="sort" placeholder="sortPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="server">服务器名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="MetatraderName" id="MetatraderName" placeholder="serverPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="serverAddress">服务器地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="MetatraderServer" id="MetatraderServer" placeholder="serverAddressPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="serverPort">服务器端口</label>
                            <div class="layui-input-block">
                                <input type="text" name="MetatraderPort" id="MetatraderPort" placeholder="serverPortPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="manageAccount">Manage账号</label>
                            <div class="layui-input-block">
                                <input type="text" name="MetatraderLogin" id="MetatraderLogin" placeholder="inputPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="managePassword">Manage密码</label>
                            <div class="layui-input-block">
                                <input type="text" name="MetatraderPassword" id="MetatraderPassword" placeholder="inputPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="accountStartNo">账号起始编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="StartLogin" id="StartLogin" placeholder="accountStartNoPrompt" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs6" style="height: 70px;">
                            <label class="layui-form-label" lay-event="accountEndNo">账号结束编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="EndLogin" id="EndLogin" placeholder="accountEndNoPrompt" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                                <button class="layui-btn" lay-submit="" lay-filter="submit-form-test">测试连接</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
